package game.assist.diablo3.adapter;

import game.assist.diablo3.R;
import game.assist.diablo3.data.vo.News;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NewsAdapter extends BaseAdapter{
	private Context context;
	private ArrayList<News> newsArray;
	public NewsAdapter(Context context, ArrayList<News> newsArray) {
		this.context = context;
		this.newsArray = newsArray;
	}

	@Override
	public int getCount() {
		if(newsArray==null||newsArray.size()==0)
			return 0;
		else
			return newsArray.size();
	}

	@Override
	public Object getItem(int position) {
		return newsArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		NewsHolder holder;
		if(convertView == null) {
			convertView  = LayoutInflater.from(context).inflate(R.layout.news_item, null);
			holder = new NewsHolder();
			holder.title = (TextView) convertView.findViewById(R.id.newsItemTitle);
			convertView.setTag(holder);
		}else {
			holder = (NewsHolder) convertView.getTag();
		}
		holder.title.setText(newsArray.get(position).getTitle());
		return convertView;
	}
	
	class NewsHolder {
		TextView title;
	}
}
